package com.wondertek.common.util.base;

import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import com.aliyun.tea.TeaException;
import com.wondertek.common.config.SmsConfig;
import lombok.extern.slf4j.Slf4j;

/**
 * @author xqs
 */
@Slf4j
public class SmsUtil {

    public static void sendMessage(String mobile,String content) throws Exception {
        SmsConfig smsConfig = SpringUtil.getApplicationContext().getBean(SmsConfig.class);
        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                .setAccessKeyId(smsConfig.getAccessKeyId())
                .setAccessKeySecret(smsConfig.getAccessKeySecret());
        config.endpoint = smsConfig.getEndpoint();
        config.setRegionId(smsConfig.getRegionId());
        com.aliyun.dysmsapi20170525.Client client = new com.aliyun.dysmsapi20170525.Client(config);
        try {
            com.aliyun.dysmsapi20170525.models.SendSmsRequest sendSmsRequest = new com.aliyun.dysmsapi20170525.models.SendSmsRequest()
                    .setPhoneNumbers(mobile)
                    .setSignName(smsConfig.getSignName())
                    .setTemplateParam("{\"code\":\""+content+"\"}")
                    .setTemplateCode(smsConfig.getTemplateCode());
            //client.sendSms(sendSmsRequest);
        } catch (TeaException error) {
            throw error;
        }
    }

}
